/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.zrnecko.bowlingnumbers.entity;

import javax.el.ELException;
import org.jboss.seam.mock.SeamTest;
import org.testng.Assert;
import org.testng.annotations.Test;

/**
 *
 * @author zrnecko
 */
@Test(groups = {"entity", "validation"})
public class FrameDetailsValidation extends SeamTest {

	@Test(groups = {"positive"})
	public void PerfectGameTest() throws Exception {
		new ComponentTest() {

			@Override
			protected void testComponents() throws Exception {
				String frameDetails = "X|X|X|X|X|X|X|X|X|XXX";
				setValue("#{game.frameDetails}", frameDetails);
				invokeMethod("#{gamesbean.saveGame}");
				Assert.assertEquals(getValue("#{outGame.frameDetails}"), frameDetails);
			}
		}.run();
	}

	@Test(groups = {"positive"})
	public void EmptyStringTest() throws Exception {
		new ComponentTest() {

			@Override
			protected void testComponents() throws Exception {
				String frameDetails = "";
				setValue("#{game.frameDetails}", frameDetails);
				invokeMethod("#{gamesbean.saveGame}");
				Assert.assertEquals(getValue("#{outGame.frameDetails}"), frameDetails);
			}
		}.run();
	}

	@Test(groups = {"positive"})
	public void GutterGameTest() throws Exception {
		new ComponentTest() {

			@Override
			protected void testComponents() throws Exception {
				String frameDetails = "--|--|--|--|--|--|--|--|--|--";
				setValue("#{game.frameDetails}", frameDetails);
				invokeMethod("#{gamesbean.saveGame}");
				Assert.assertEquals(getValue("#{outGame.frameDetails}"), frameDetails);
			}
		}.run();
	}

	@Test(groups = {"positive"})
	public void NineGameTest() throws Exception {
		new ComponentTest() {

			@Override
			protected void testComponents() throws Exception {
				String frameDetails = "9/|9/|9/|9/|9/|9/|9/|9/|9/|9/9";
				setValue("#{game.frameDetails}", frameDetails);
				invokeMethod("#{gamesbean.saveGame}");
				Assert.assertEquals(getValue("#{outGame.frameDetails}"), frameDetails);
			}
		}.run();
	}

	@Test(groups = {"positive"})
	public void SomeOrdinaryGameTest() throws Exception {
		new ComponentTest() {

			@Override
			protected void testComponents() throws Exception {
				String frameDetails = "9/|X|7-|X|X|X|9/|8-|63|X91";
				setValue("#{game.frameDetails}", frameDetails);
				invokeMethod("#{gamesbean.saveGame}");
				Assert.assertEquals(getValue("#{outGame.frameDetails}"), frameDetails);
			}
		}.run();
	}

	@Test(groups = {"negative"}, expectedExceptions = {ELException.class})
	public void GibberishTest() throws Exception {
		new ComponentTest() {

			@Override
			protected void testComponents() throws Exception {
				String frameDetails = "adlfjakldfjasldfja41341";
				setValue("#{game.frameDetails}", frameDetails);
				invokeMethod("#{gamesbean.saveGame}");
				Assert.fail();
			}
		}.run();

	}

	@Test(groups = {"negative"}, expectedExceptions = {ELException.class})
	public void SomeInvalidFramesTest() throws Exception {
		new ComponentTest() {

			@Override
			protected void testComponents() throws Exception {
				String frameDetails = "76|39|89|48|91|59|88|55|92|78";
				setValue("#{game.frameDetails}", frameDetails);
				invokeMethod("#{gamesbean.saveGame}");
				Assert.fail();
			}
		}.run();

	}

	@Test(groups = {"negative"}, expectedExceptions = {ELException.class})
	public void SomeZeroesTest() throws Exception {
		new ComponentTest() {

			@Override
			protected void testComponents() throws Exception {
				String frameDetails = "X|X|00|00|X|X|X|X|X|000";
				setValue("#{game.frameDetails}", frameDetails);
				invokeMethod("#{gamesbean.saveGame}");
				Assert.fail();
			}
		}.run();

	}
}
